export const countdownCaptcha = {
  data() {
    return {
      isRun: false, // 是否进入验证码倒计时
      runTime: 60, // 验证码倒计时
    }
  },
  created() {
    let localRunTime = localStorage.getItem('localRunTime')
    if (localRunTime > 0 && localRunTime <= this.runTime) {
      this.runTime = localRunTime
      this.isRun = true
      this.autoTimer = setInterval(() => {
        if (this.runTime === 0) {
          this.runTime = 60;
          this.isRun = false;
          clearInterval(this.autoTimer);
          return;
        }
        this.runTime--;
        localStorage.setItem('localRunTime', this.runTime)
      }, 1000);
    }
  },
  methods: {
    // 进入计时60s
    changeIsRun() {
      this.isRun = true;
      localStorage.setItem('localRunTime', this.runTime)
      this.autoTimer = setInterval(() => {
        if (this.runTime === 0) {
          this.runTime = 60;
          this.isRun = false;
          clearInterval(this.autoTimer);
          return;
        }
        this.runTime--;
        localStorage.setItem('localRunTime', this.runTime)
      }, 1000);
    }
  }
}